package io.renren.modules.car.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.car.entity.CarShopMoneyEntity;
import io.renren.modules.car.service.CarShopMoneyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 车辆商铺分赃表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2021-09-17 11:28:03
 */
@RestController
@RequestMapping("car/carshopmoney")
public class CarShopMoneyController {
    @Autowired
    private CarShopMoneyService carShopMoneyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("car:carshopmoney:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = carShopMoneyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("car:carshopmoney:info")
    public R info(@PathVariable("id") Integer id){
        CarShopMoneyEntity carShopMoney = carShopMoneyService.getById(id);

        return R.ok().put("carShopMoney", carShopMoney);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("car:carshopmoney:save")
    public R save(@RequestBody CarShopMoneyEntity carShopMoney){
        Date date = new Date();
        carShopMoney.setCreateTime(date);
        carShopMoney.setUpdateTime(date);
        carShopMoneyService.save(carShopMoney);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("car:carshopmoney:update")
    public R update(@RequestBody CarShopMoneyEntity carShopMoney){
        ValidatorUtils.validateEntity(carShopMoney);
        Date date = new Date();
        carShopMoney.setUpdateTime(date);
        carShopMoneyService.updateById(carShopMoney);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("car:carshopmoney:delete")
    public R delete(@RequestBody Integer[] ids){
        carShopMoneyService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
